// tslint:disable
import { AppGlobalService } from 'src/app/shared/service/app-global.service';
import { Component, Input, OnInit } from '@angular/core';
import { Subscription } from "rxjs";
import { HttpService } from 'src/app/shared/service/http.service';
import { MessageService } from 'src/app/shared/service/message.service';

@Component({
  selector: 'app-performance-total',
  templateUrl: './performance-total.component.html',
  styleUrls: ['./performance-total.component.scss'],
})
export class PerformanceTotalComponent

  implements OnInit {
  @Input() tagData: any;
  params: any;
  // 声明订阅对象
  subscription: Subscription = null;
  constructor(
    private message: MessageService,
    private httpService: HttpService,
    private appGlobalService: AppGlobalService
  ) { }

  ngOnInit() {
    if (!this.subscription && this.tagData.key) {
      this.message.clearMessage();
      // 获取筛选参数
      this.subscription = this.message.getMessage().subscribe(param => {
        if (param === undefined) {
          return;
        }
        // 参数
        this.params = {
          sessionId: localStorage.getItem("sessionId"),
          id: this.tagData.key
        };
        this.params.content = param;
        // 页面数据参数
        this.httpService.post(
          "application/submit",
          this.params,
          res => {

            // 请求数据成功
            if (res.success) {
              // 筛选数据
              if (res.data.listData) {
                this.tagData.listData = res.data.listData;
                this.tagData.data = null;
                this.tagData.headData = null;
              } else {
                this.tagData.listData = null;
                this.tagData.data = res.data.data;
                this.tagData.headData = res.data.headData;
              }

              // 自动回到顶部
              setTimeout(() => {
                const el = document.getElementById('information0');
                if (el) {
                  el.scrollIntoView(true);
                }
              }, 200);
            } else {
              // 请求数据失败
              this.appGlobalService.showToast(res.message, 2000, "middle");
            }
          },
          err => {
            // 请求数据失败
            this.appGlobalService.showToast(err.message, 2000, "middle");
          }
        );
      });
      // this.demoData();
    }
  }
  ngOnDestroy(): void {
    if (this.subscription) {
      this.subscription.unsubscribe();
    }
  }
  detailClick(link) {
    this.appGlobalService.openPage(link);
  }
  demoData() {
    this.tagData = {
      type: "tag",
      style: "appMyAchieveTag",
      name: "appMyAchieveTag",
      key: "e257e284-4594-4c45-9ab3-533a5f6ad7a5",
      listData: [
        {
          headData: [
            {
              cssStyle: "display:flex;flex-direction:column;justify-content:space-between;flex-basis:4rem;",
              label: "",
              value: "合计",
              valueCssStyle: "background: rgb(39, 40, 46);border-radius: 0.56rem;height: 1rem;color: rgb(255, 255, 255);text-align: center;padding: 0rem 0.31rem;font-size: 0.1rem;line-height: 1rem;font-weight: normal;width: fit-content;"
            },
            {
              cssStyle: "text-align:right;flex-grow: 1;",
              label: "单量",
              value: "0",
              valueCssStyle: "font-size: 1.38rem;font-weight: bold;color: #27282E;"
            },
            {
              cssStyle: "flex-basis:8rem;text-align:right",
              label: "业绩",
              value: "0",
              valueCssStyle: "font-size: 1.38rem;font-weight: bold;color: #27282E;"
            }
          ],
          data: [
            {
              link: {
                type: "modal",
                params: {
                  ":currentUserId()": "5f2d04ecf750d20001b7679b",
                  statistic_achievement_plugin_id: "1",
                  statistic_achievement_type: "6",
                  minstatistic_achievement_quote_payment_time: "2020-09-18 00:00:00",
                  delayed: "1000",
                  maxstatistic_achievement_quote_payment_time: "2020-09-18 23:59:59"
                },
                target: "161496"
              },
              items: [
                {
                  cssStyle: "flex-basis:4rem;",
                  label: "转让"
                },
                {
                  cssStyle: "text-align:right;flex-grow: 1;",
                  label: "0"
                },
                {
                  cssStyle: "flex-basis:8rem;text-align:right;",
                  label: "0"
                }
              ]
            },
            {
              link: {
                type: "modal",
                params: {
                  ":currentUserId()": "5f2d04ecf750d20001b7679b",
                  statistic_achievement_plugin_id: "2",
                  statistic_achievement_type: "6",
                  minstatistic_achievement_quote_payment_time: "2020-09-18 00:00:00",
                  delayed: "1000",
                  maxstatistic_achievement_quote_payment_time: "2020-09-18 23:59:59"
                },
                target: "161496"
              },
              items: [
                {
                  cssStyle: "flex-basis:4rem;",
                  label: "出租"
                },
                {
                  cssStyle: "text-align:right;flex-grow: 1;",
                  label: "0"
                },
                {
                  cssStyle: "flex-basis:8rem;text-align:right;",
                  label: "0"
                }
              ]
            },
            {
              link: {
                type: "modal",
                params: {
                  ":currentUserId()": "5f2d04ecf750d20001b7679b",
                  statistic_achievement_plugin_id: "3",
                  statistic_achievement_type: "6",
                  minstatistic_achievement_quote_payment_time: "2020-09-18 00:00:00",
                  delayed: "1000",
                  maxstatistic_achievement_quote_payment_time: "2020-09-18 23:59:59"
                },
                target: "161496"
              },
              items: [
                {
                  cssStyle: "flex-basis:4rem;",
                  label: "选址"
                },
                {
                  cssStyle: "text-align:right;flex-grow: 1;",
                  label: "0"
                },
                {
                  cssStyle: "flex-basis:8rem;text-align:right;",
                  label: "0"
                }
              ]
            }
          ]
        },
        {
          headData: [
            {
              cssStyle: "display:flex;flex-direction:column;justify-content:space-between;flex-basis:4rem;",
              label: "",
              value: "合计",
              valueCssStyle: "background: rgb(39, 40, 46);border-radius: 0.56rem;height: 1rem;color: rgb(255, 255, 255);text-align: center;padding: 0rem 0.31rem;font-size: 0.1rem;line-height: 1rem;font-weight: normal;width: fit-content;"
            },
            {
              cssStyle: "text-align:right;flex-grow: 1;",
              label: "单量",
              value: "0",
              valueCssStyle: "font-size: 1.38rem;font-weight: bold;color: #27282E;"
            },
            {
              cssStyle: "flex-basis:8rem;text-align:right",
              label: "业绩",
              value: "0",
              valueCssStyle: "font-size: 1.38rem;font-weight: bold;color: #27282E;"
            }
          ],
          data: [
            {
              link: {
                type: "modal",
                params: {
                  ":currentUserId()": "5f2d04ecf750d20001b7679b",
                  statistic_achievement_plugin_id: "1",
                  statistic_achievement_type: "6",
                  minstatistic_achievement_quote_payment_time: "2020-09-18 00:00:00",
                  delayed: "1000",
                  maxstatistic_achievement_quote_payment_time: "2020-09-18 23:59:59"
                },
                target: "161496"
              },
              items: [
                {
                  cssStyle: "flex-basis:4rem;",
                  label: "转让"
                },
                {
                  cssStyle: "text-align:right;flex-grow: 1;",
                  label: "0"
                },
                {
                  cssStyle: "flex-basis:8rem;text-align:right;",
                  label: "0"
                }
              ]
            },
            {
              link: {
                type: "modal",
                params: {
                  ":currentUserId()": "5f2d04ecf750d20001b7679b",
                  statistic_achievement_plugin_id: "2",
                  statistic_achievement_type: "6",
                  minstatistic_achievement_quote_payment_time: "2020-09-18 00:00:00",
                  delayed: "1000",
                  maxstatistic_achievement_quote_payment_time: "2020-09-18 23:59:59"
                },
                target: "161496"
              },
              items: [
                {
                  cssStyle: "flex-basis:4rem;",
                  label: "出租"
                },
                {
                  cssStyle: "text-align:right;flex-grow: 1;",
                  label: "0"
                },
                {
                  cssStyle: "flex-basis:8rem;text-align:right;",
                  label: "0"
                }
              ]
            },
            {
              link: {
                type: "modal",
                params: {
                  ":currentUserId()": "5f2d04ecf750d20001b7679b",
                  statistic_achievement_plugin_id: "3",
                  statistic_achievement_type: "6",
                  minstatistic_achievement_quote_payment_time: "2020-09-18 00:00:00",
                  delayed: "1000",
                  maxstatistic_achievement_quote_payment_time: "2020-09-18 23:59:59"
                },
                target: "161496"
              },
              items: [
                {
                  cssStyle: "flex-basis:4rem;",
                  label: "选址"
                },
                {
                  cssStyle: "text-align:right;flex-grow: 1;",
                  label: "0"
                },
                {
                  cssStyle: "flex-basis:8rem;text-align:right;",
                  label: "0"
                }
              ]
            }
          ]
        },
      ],
    };
  }
}
